package wondersgroup.hsswidget.dispatch;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

/**
 * Created by Administrator on 2016/12/29.
 */

public class ChildScrollView extends ScrollView {
    public ChildScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public ChildScrollView(Context context) {
        super(context);
    }

    public ChildScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public ScollViewTopListener listener;

    public void setListener(ScollViewTopListener listener) {
        this.listener = listener;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_MOVE:
                int y = getScrollY();
                if (y == 0){
                    //允许父View进行事件拦截
                    getParent().requestDisallowInterceptTouchEvent(true);
                    if (listener !=null){
                        listener.checIsTop(true);
                    }
                }else {
                    //禁止父View进行事件拦截
                    getParent().requestDisallowInterceptTouchEvent(false);
//                    if (listener !=null){
//                        listener.checIsTop(false);
//                    }
                }
                break;
            case MotionEvent.ACTION_UP:
                break;
        }
        return super.onTouchEvent(ev);
    }

    public static interface ScollViewTopListener{
        void checIsTop(boolean flag);
    }

}
